package com.zhang.bingmei_incomeexpenditure.service.factory;

import com.zhang.bingmei_incomeexpenditure.mapper.IncomeExpenditureMapper;
import com.zhang.bingmei_incomeexpenditure.service.chain.Impl.RequiredFieldValidationHandler;
import com.zhang.bingmei_incomeexpenditure.service.chain.Impl.UniquenessValidationHandler;
import com.zhang.bingmei_incomeexpenditure.service.chain.Impl.YearValidationHandler;
import com.zhang.bingmei_incomeexpenditure.service.chain.ValidationHandler;

// 校验链工厂
public class ValidationChainFactory {
    public static ValidationHandler buildUpdateValidationChain(IncomeExpenditureMapper mapper) {
        ValidationHandler requiredHandler = new RequiredFieldValidationHandler();
        ValidationHandler yearHandler = new YearValidationHandler();
        ValidationHandler uniquenessHandler = new UniquenessValidationHandler(mapper);

        // 构建链：必填项 → 年份 → 唯一性
        requiredHandler.setNext(yearHandler);
        yearHandler.setNext(uniquenessHandler);
        return requiredHandler;
    }
}